<template>
	<view class="mainContent" style="height: 100vh;">
		<view class="header">
			<view class="modular">
				<view class="search">
					<image src="@/static/img/quickly/healthStatus/search@2x.png" mode=""></image>
					<input type="text" placeholder="姓名" v-model="searchVal" @blur="search">
				</view>
			</view>
			
			<view class="navigatorModular">
				<view class="classification">
					<!-- :style="{'transform': 'translateX('+((currentIndex)*-40)+'px)'}" -->
					<div class="classifcation-a" >
						<text :class="currentIndex == index ? 'on' : ''" v-for="(item,index) in classifcationArr" @click="tabClick(index)" :key="index">{{item}} 
							<image src="@/static/img/quickly/healthStatus/dropDown@2x.png" v-show="currentIndex == index"></image>
						</text>
					</div>
				</view>
				<image src="@/static/img/healthStatus/split@2x.png" class="split"></image>
				<image src="@/static/img/quickly/healthStatus/open@2x.png" class="open" @click="bulletFrame = !bulletFrame"></image>
			</view>
		</view>
		
		<view class="listMular">
			<uni-swipe-action v-if="list.length > 0">
				<view class="box" v-for="(item,index) in list" :key="index">
					<image src="@/static/img/quickly/healthStatus/number@2x.png" class="identifier"></image>
					<uni-swipe-action-item :right-options="options"  @click="bindClick(item)">
						<view class="top">
							<text class="assementNumber">{{item.status == 1 ? '评估编号' : item.sn}}</text>
							<text :class="item.status == 1 ? 'dataTime1' : 'dataTime'">{{item.status == 1? '未评估' : item.fillFormDate}}</text>
						</view>
						<view class="bottom">
							<view class="nameBox">
								<text class="userName">{{item.userName}}</text>
							</view>
							<view class="buttonBox">	
								<view class="qsDetail" @click="detail(item)">详情</view>
								<view class="applyFor" v-if="item.status == 1" @click="creat(item)">生成评估</view>
								<view class="generating" v-else-if="item.status == 2">生成中</view>
								<view class="viewAssessment" v-else @click="read(item)">查看报告</view>
							</view>
						</view>
					</uni-swipe-action-item>
				</view>
			</uni-swipe-action>
			
			<view class="noData" v-else>
				<image src="@/static/img/healthStatus/none.png"></image>
				<view>您还没有评估文件~</view>
			</view>
		</view>	
		
		<view class="location">
			<image src="@/static/img/quickly/healthStatus/add@2x.png"  @click="addQuestion"></image>
		</view>
		
		<reportImgType2 ref="reportImgType2" :info="info" v-if="currentIndex == 2 || currentIndex == 3"></reportImgType2>
		<reportImgType1 ref="reportImgType1" :info="info" v-if="currentIndex == 0"></reportImgType1>
		<reportImgType3 ref="reportImgType3" :info="info" v-if="currentIndex == 5"></reportImgType3>
		<reportImgType4 ref="reportImgType4" :info="info" v-if="currentIndex == 4"></reportImgType4>
		<reportImgType5 ref="reportImgType5" :info="info" v-if="currentIndex == 1"></reportImgType5>
		<reportImgType6 ref="reportImgType6" :info="info" v-if="currentIndex == 6"></reportImgType6>
		
		<!-- 自定义弹框 -->
		<view class="mask" v-if="bulletFrame" @click="bulletFrame = false"></view>
		<view class="uniPop" v-if="bulletFrame">
			<view class="navigatorModular" v-for="(aitem,aindex) in classifcationArr" :key="aindex" @click="navigationClick(aindex)">
				<image src='@/static/img/healthStatus/lifeOn@2x.png' v-if="aindex == 0 && currentIndex == 0"></image>
				<image src='@/static/img/healthStatus/life@2x.png' v-else-if="aindex == 0"></image>
				<image src="@/static/img/healthStatus/examinationSelect@2x.png" v-if="aindex == 1 && currentIndex == 1"></image>
				<image src="@/static/img/healthStatus/examination@2x.png" v-else-if="aindex == 1"></image>
				<image src="@/static/img/healthStatus/heartOn@2x.png" v-if="aindex == 2 && currentIndex == 2"></image>
				<image src="@/static/img/healthStatus/heart@2x.png" v-else-if="aindex == 2"></image>
				<image src="@/static/img/healthStatus/accomplishmentOn@2x.png" v-if="aindex == 3 && currentIndex == 3"></image>
				<image src="@/static/img/healthStatus/accomplishment@2x.png" v-else-if="aindex == 3"></image>
				<image src="@/static/img/healthStatus/anxiousOn@2x.png" v-if="aindex == 4 && currentIndex == 4"></image>
				<image src="@/static/img/healthStatus/anxious@2x.png" v-else-if="aindex == 4"></image>
				<image src="@/static/img/healthStatus/depressedOn@2x.png" v-if="aindex == 5 && currentIndex == 5"></image>
				<image src="@/static/img/healthStatus/depressed@2x.png" v-else-if="aindex == 5"></image>
				<image src="@/static/img/healthStatus/medicalOn@2x.png" v-if="aindex == 6 && currentIndex == 6"></image>
				<image src="@/static/img/healthStatus/medical@2x.png" v-else-if="aindex == 6"></image>
				<view :class="aindex == currentIndex ? 'checked' : ''">{{aitem}}</view>
			</view>
		</view>
	</view>
</template>
<script>
	import reportImgType2 from './reportImgType2.vue'
	import reportImgType1 from './reportImgType1.vue'
	import reportImgType3 from './reportImgType3.vue'
	import reportImgType4 from './reportImgType4.vue'
	import reportImgType5 from './examined/reportImg.vue'
	import reportImgType6 from './reportImgType5.vue'
	export default{
		components:{
			reportImgType2,
			reportImgType1,
			reportImgType3,
			reportImgType4,
			reportImgType5,
			reportImgType6
		},
		data() {
			return {
				classifcationArr:['生活方式','体检指标','心理健康','健康素养','焦虑状态','抑郁状态','中医体质'],
				currentIndex:0,
				list:[],
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#EE2437' // 删除按钮背景  红的
					}
				}],
				info:{},
				bulletFrame: false, //自定义弹框
				page:1,
				isNull:false,
				searchVal:''
			}
		},
		onReachBottom(){
			if(this.isNull){
				return;
			}
			this.page = Number(this.page) + 1
			const upload = Number(this.currentIndex)+1 
			this.getData(upload,{pageIndex:this.page,pageSize:10})
		},
		onLoad(options){
			if(options.current){
				this.currentIndex = options.current
				this.tabClick(Number(options.current))
			}else{
				this.tabClick(0)
			}
		},
		methods:{
			search(){
				this.list = []
				this.isNull = false
				this.page = 1
				const upload = Number(this.currentIndex)+1 
				this.getData(upload,{pageIndex:1,pageSize:10,userName:this.searchVal})
			},
			navigationClick(e) {
				uni.pageScrollTo({
					scrollTop:0
				})
				this.list = []
				this.currentIndex = e,
				this.bulletFrame = false
				this.page = 1
				const upload = Number(e)+1
				this.getData(upload,{pageIndex:1,pageSize:10,userName:this.searchVal})
			},
			// 申请评估
			creat(item){
				const _this = this;
				_this.info = item
				uni.showLoading({title:'加载中'})
				setTimeout(()=>{
					uni.hideLoading()
					if(_this.currentIndex == 1){
						_this.$refs.reportImgType5.toImg().then((base64)=>{
							var arr = base64.split(',')
							var mime = arr[0].match(/:(.*?);/)[1]
							var bstr = atob(arr[1]) 
							var nn = bstr.length 
							var u8arr = new Uint8Array(nn);
							while(nn--){
								u8arr[nn] = bstr.charCodeAt(nn);
							}
							var obj1 = new Blob([u8arr], {type:mime});
							_this.$api.HealthExaminationReportUploadWord({fileOne:obj1},item.id).then((ares) => {
								uni.hideLoading()
								if(ares.returnCode == 200){
									window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+ares.result.url
								}
							})
						})
					}else{
						_this.$refs[item.upload == 1?'reportImgType1':item.upload == 3 || item.upload == 4?'reportImgType2':item.upload == 6 ?'reportImgType3':item.upload == 5?'reportImgType4':item.upload == 7?'reportImgType6':''].toImg().then((base64)=>{
							var arr = base64.split(',')
							var mime = arr[0].match(/:(.*?);/)[1]
							var bstr = atob(arr[1]) 
							var nn = bstr.length 
							var u8arr = new Uint8Array(nn);
							while(nn--){
								u8arr[nn] = bstr.charCodeAt(nn);
							}
							var obj1 = new Blob([u8arr], {type:mime});
							_this.$api.healthAssessmentuploadWord({fileOne:obj1},item.id).then((res) => {
								if(JSON.parse(res.data).returnCode == 200){
									_this.getData(item.upload,{pageIndex:1,pageSize:10})
									window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+JSON.parse(res.data).result.url
								}
							})
						})
					}
				},1000)
			},
			tabClick(e) {
				uni.pageScrollTo({
					scrollTop:0
				})
				this.currentIndex = e
				this.page = 1
				this.list = []
				const upload = Number(e)+1
				this.getData(upload,{pageIndex:1,pageSize:10,userName:this.searchVal})
			},
			getData(e,data){
				const _this = this;
				data.upload = e
				if(e == 2){
					_this.$api.HealthExaminationReportList(data).then((res)=>{
						_this.list = _this.list.length > 0 ? _this.list.concat(res.data.result.elements) : res.data.result.elements
						if(_this.list.length >= res.data.result.totalCount){
							_this.isNull = true
						}else{
							_this.isNull = false
						}
					})
				}else{
					_this.$api.healthAssessmentList(data).then((res)=>{
						_this.list = _this.list.length > 0 ? _this.list.concat(res.data.result.elements) : res.data.result.elements
						if(_this.list.length >= res.data.result.totalCount){
							_this.isNull = true
						}else{
							_this.isNull = false
						}
					})
				}
			},
			addQuestion() {
				uni.navigateTo({
					url:'/pages/quickly/healthStatus/navigatorBar'
				})
			},
			// 问卷详情
			detail(item){
				if(item.status == 1){
					// 编辑
					if(this.currentIndex == 2){
						uni.navigateTo({url:`/pages/quickly/psychology/index?edit=1&id=${item.id}`})
					}else if(this.currentIndex == 3){
						uni.navigateTo({url:`/pages/quickly/healthStatus/accomplishment/add?edit=1&id=${item.id}`})
					}else if(this.currentIndex == 0){
						uni.navigateTo({url:`/pages/quickly/healthStatus/lifeStyle/index?edit=1&id=${item.id}`})
					}else if(this.currentIndex == 4){
						uni.navigateTo({url:`/pages/quickly/healthStatus/anxious/index?edit=1&id=${item.id}`})
					}else if(this.currentIndex == 5){
						uni.navigateTo({url:`/pages/quickly/healthStatus/depressed/index?edit=1&id=${item.id}`})
					}else if(this.currentIndex == 1){
						uni.navigateTo({url:`/pages/quickly/healthStatus/examined/index?edit=1&id=${item.id}`})
					}else if(this.currentIndex == 6){
						uni.navigateTo({url:`/pages/quickly/healthStatus/chineseMedicine/index?id=${item.id}&userId=${item.userId}`})
					}
				}else{
					// 已签发-查看详情
					if(this.currentIndex == 2){
						uni.navigateTo({url:`/pages/quickly/psychology/toView?id=${item.id}&userId=${item.userId}`})
					}else if(this.currentIndex == 3){
						uni.navigateTo({url:`/pages/quickly/healthStatus/accomplishment/toView?id=${item.id}&userId=${item.userId}`})
					}else if(this.currentIndex == 0){
						uni.navigateTo({url:`/pages/quickly/healthStatus/lifeStyle/toView?id=${item.id}&userId=${item.userId}`})
					}else if(this.currentIndex == 4){
						uni.navigateTo({url:`/pages/quickly/healthStatus/anxious/toView?id=${item.id}&userId=${item.userId}`})
					}else if(this.currentIndex == 5){
						uni.navigateTo({url:`/pages/quickly/healthStatus/depressed/toView?id=${item.id}&userId=${item.userId}`})
					}else if(this.currentIndex == 1){
						uni.navigateTo({url:`/pages/quickly/healthStatus/examined/toView?id=${item.id}&userId=${item.userId}`})
					}else if(this.currentIndex == 6){
						uni.navigateTo({url:`/pages/quickly/healthStatus/chineseMedicine/toView?id=${item.id}&userId=${item.userId}`})
					}
				}
			},
			bindClick(item){
				const _this = this;
				if(this.currentIndex == 1){
					_this.$api.HealthExaminationReportDelete(item.id).then((res)=>{
						_this.tabClick(_this.currentIndex)
					})
				}else{
					_this.$api.healthAssessmentDelete(item.id).then((res)=>{
						_this.tabClick(_this.currentIndex)
					})
				}
			},
			// 查看报告
			read(item){
				window.location.href = 'http://health.jlm12580.com/web/viewer.html?file='+item.url
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import '@/static/css/quickly/healthStatus/navigation.scss';
	/deep/ .uni-swipe_box{
		display: block !important;
	}
	/deep/.uni-swipe_button{
		padding: 0 20rpx;
		margin-left: 10rpx;
	}
	.listMular{
		padding-bottom: 70rpx;
	}
</style>
